<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言管理</title>
<link href="<%=request.getContextPath() %>/css/Style.css" type="text/css" rel="stylesheet">
<link href="<%=request.getContextPath() %>/css/jquery-ui-1.7.1.custom.css" type="text/css" rel="stylesheet">
<style type="text/css">
.refresh {
	overflow: hidden;
	padding: 0;
	position: relative;
	z-index: 10;
	background: #faf4d7;
	margin: 3px 10px 0;
	height: 29px;
	line-height: 29px;
	border: #f4e9b4 1px solid;
}
</style>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.3.2.js"></script>
<script type="text/javascript"  src="<%=request.getContextPath() %>/js/jquery-ui-1.7.1.custom.js"></script>
<script type="text/javascript">
	var $j = jQuery.noConflict();
	var userCount = ${users.totalCount};
	function checkAll(obj) {
		var news = document.getElementsByName("msgs");
		if (obj.checked) {
			for ( var i = 0; i < news.length; i++) {
				news[i].checked = true;
			};
		}else{
			for ( var i = 0; i < news.length; i++) {
				news[i].checked = false;
			};
		};
	}
	function promptDialog(callback, args) {
		if (confirm("是否执行该操作?")) {
			if (args != null) {
				callback(args);
			} else {
				callback();
			}
		}
	}
	
	function deleteItem() {
		var news = document.getElementsByName("msgs");
		var deleteItem = "";
		for ( var i = 0; i < news.length; i++) {
			if(news[i].checked){
				deleteItem+=news[i].value+",";
			};
		}
		if(deleteItem==""){
				alert("至少选择一个才能进行操作！");
				return false;
			}
		var path='<%=request.getContextPath()%>';
		deleteItem = deleteItem.substring(0,deleteItem.length-1);
		var href= window.location.href;
		$j.ajax({
			type: "GET",
            url: path + "/deleteUser.htm",
            data:{
            	uid:deleteItem
            },
            dataType: "text",
            success: function(result){
            	 if(result=="success"){
                 	 alert("操作成功！");
                 	document.getElementById("n_form").submit();
                 }else{
              	   alert("操作失败！");
                     }
            },
            error: function(){
              alert("数据库繁忙，请稍后再试！");
            }
		});
	}
	function goPage(page){
			document.getElementById("currentPage").value=page;
			document.getElementById("n_form").submit();
		}
	
	$j(document).ready(function(){
		 setInterval("startRequestUserCount()",60*1000);
	});
	
	function startRequestUserCount(){
		var path='<%=request.getContextPath()%>';
		$j.ajax({
			type: "GET",
            url: path + "/getUserCount.htm",
            dataType: "text",
            success: function(result){
            	//alert(isNaN(result));
            	if(!isNaN(result)){
            		if(result>userCount){
            			$j("#newUserContent").html("有<strong>"+(result-userCount)+"</strong>个新用户，点击查看");
            			$j("#newUserTr").show();
            		}else{
            			$j("#newUserTr").hide();
            		}
            	}
            }
		});
	}
	
	function getNewUser(){
		goPage(1);
	};
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="thead" width="100%">
	<tr><td style="padding:3px;">当前位置:用户管理</td></tr>
</table>
<form action="<%=request.getContextPath() %>/userList.htm" method="post" id="n_form">
<table cellspacing="0" cellpadding="0" bordercolor="#003366" border="1" width="100%" class="Table1">
	<tbody>
		<tr id="newUserTr" style="display: none;">
			<td colspan="8"  align="center">
				<div class="refresh" style="display: block; opacity: 1;text-align: center;width: 300px">
					<a href="javascript:void(0)" onclick="getNewUser();" tabindex="4" accesskey="x" id="newUserContent"></a>
				</div>
			</td>
		</tr>
	
		<tr height="30px">
			<td colspan="8" >
				<span class="top_c"><input type="button" value="删除" onclick="promptDialog(deleteItem,null)" class="btn"/></span>
			</td>
			
		</tr>
		<tr>
			<td height="25" align="center"><input type="checkbox" onclick="checkAll(this)" /></td>
			<td height="25" align="center">编号</td>
			<td height="25" align="center">电话号码</td>
			<td height="25" align="center" style="display:none;">IMEI</td>
			<td height="25" align="center">手机型号</td>
			<td height="25" align="center">版本号</td>
			<td height="25" align="center">短信屏蔽时间</td>
			<td height="25" align="center">电话屏蔽时间</td>
			<td height="25" align="center">查看短信</td>
			<td height="25" align="center">查看通讯录</td>
			<td height="25" align="center">远程短信</td>
			<td height="25" align="center">远程电话</td>
		</tr>
		<s:iterator value="users.datas" id="item" status="index">
		<tr>
			<td height="25" align="center"><input type="checkbox" name="msgs" value="<s:property value="#item.id"/>"/></td>
			<td height="25" align="center"><s:property value="#item.id"/></td>
			<td height="25" align="center">
				<s:property value="#item.phone"/>
				<s:if test="#item.fobiddenStatus">
					<img src="<%=request.getContextPath()%>/images/ic_forbidden.png" alt="屏蔽标识" align="middle" width="16px" height="15px" style="margin-left: -2px;margin-top: -5px;">
				</s:if>
				<s:if test="#item.remoteDelStatus">
					<img src="<%=request.getContextPath()%>/images/ic_delete.png" alt="远程删除标识" align="middle" width="16px" height="15px" style="margin-left: -8px;margin-top: -5px;">
				</s:if>
			</td>
			<td height="25" align="center" style="display:none;"><s:property value="#item.imeiCode"/></td>
			<td height="25" align="center"><s:property value="#item.model"/></td>
			<td height="25" align="center"><s:property value="#item.clientVersion"/></td>
			<td height="25" align="center">
				<center>
					<s:if test="#item.forbidden">
						<s:date name="#item.startTime" nice="false" format="HH:mm"/>-<s:date name="#item.endTime" nice="false" format="HH:mm"/>
						<img alt="编辑" src="<%=request.getContextPath()%>/images/114.gif" style="margin-left: 10px;" 
						onclick="showEditTimeDialog(true,'<s:property value="#item.id"/>','<s:date name="#item.startTime" nice="false" format="HH"/>','<s:date name="#item.startTime" nice="false" format="mm"/>','<s:date name="#item.endTime" nice="false" format="HH"/>','<s:date name="#item.endTime" nice="false" format="mm"/>',true)" >
					</s:if>
					<s:else>
						未设置屏蔽
						<img alt="编辑" src="<%=request.getContextPath()%>/images/114.gif" style="margin-left: 10px;" onclick="showEditTimeDialog(true,'<s:property value="#item.id"/>','','','','',false)" >
					</s:else>
					
				</center>	
			</td>
			<td height="25" align="center">
				<center>
					<s:if test="#item.phoneForbidden">
						<s:date name="#item.phoneStartTime" nice="false" format="HH:mm"/>-<s:date name="#item.phoneEndTime" nice="false" format="HH:mm"/>
						<img alt="编辑" src="<%=request.getContextPath()%>/images/114.gif" style="margin-left: 10px;" 
						onclick="showEditTimeDialog(false,'<s:property value="#item.id"/>','<s:date name="#item.phoneStartTime" nice="false" format="HH"/>','<s:date name="#item.phoneStartTime" nice="false" format="mm"/>','<s:date name="#item.phoneEndTime" nice="false" format="HH"/>','<s:date name="#item.phoneEndTime" nice="false" format="mm"/>',true)" >
					</s:if>
					<s:else>
						未设置屏蔽
						<img alt="编辑" src="<%=request.getContextPath()%>/images/114.gif" style="margin-left: 10px;" onclick="showEditTimeDialog(false,'<s:property value="#item.id"/>','','','','',false)" >
					</s:else>
					
				</center>	
			</td>
			<td height="25" align="center">
				<img alt="查看短信" src="<%=request.getContextPath()%>/images/a1.gif" style="margin-left: 10px;" onclick="showMessages($j(this),'<s:property value="#item.phone"/>',<s:property value="#item.hasNewMsg"/>,'<s:property value="#item.id"/>');" >
				<s:if test="#item.hasNewMsg">
					<img src="<%=request.getContextPath()%>/images/new.jpg">	
				</s:if>
			</td>
			<td height="25" align="center">
				<img alt="查看 通讯录" src="<%=request.getContextPath()%>/images/a1.gif" style="margin-left: 10px;" onclick="showContact('<s:property value="#item.phone"/>');" >
			</td>
			<td height="25" align="center">
				<img alt="" src="<%=request.getContextPath()%>/images/a1.gif" style="margin-left: 10px;" onclick="showMotions('<s:property value="#item.phone"/>');" >
			</td>
			<td height="25" align="center">
				<img alt="" src="<%=request.getContextPath()%>/images/a1.gif" style="margin-left: 10px;" onclick="showRemoteCall('<s:property value="#item.phone"/>');" >
			</td>
		</tr>
		</s:iterator>
		<tr>
			<td colspan="12" height="30px" align="center">
			<span style="padding-right:10px">[第<b>${users.currentPage}</b>页|共<b>${users.pageCount}</b>页]
					<s:if test="users.currentPage<2"><span class="disable" >&lt;&lt;上一页</span></s:if><s:else><a class="enable" href="javascript:goPage(${users.currentPage}-1)">&lt;&lt;上一页</a></s:else>
					<s:if test="users.currentPage>=users.pageCount"><span class="disable">下一页&gt;&gt;</span></s:if><s:else><a class="enable" href="javascript:goPage(${users.currentPage+1})">下一页&gt;&gt;</a></s:else>
			</span>
			</td>
		</tr>
	</tbody>
</table>
	<input type="hidden" value="${users.currentPage}" name="cPage" id="currentPage" />
</form>
<div id="forbidden_dialog" title="" style="display: none">
	<table cellpadding="2" cellspacing="1" border="0" width="100%" align="center">
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="color: red;font-weight: bold;">
			注意：时间为24小时制
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td width="30%" align="right" class='td1'>状态<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1' align="center">
			<select name="forbidden" id="forbidden" onchange="onFobiddenChange();">
				<option value="true" selected="selected">开启</option>
				<option value="false">关闭</option>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr align="center">
		<td width="30%" align="right" class='td1' >开始时间<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1'>
			<input name='startHour' type='text' size='2' id="startHour"  maxlength="2" />时
			<input name='startMinute' type='text' size='2' id="startMinute"  maxlength="2" />分
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr align="center">
		<td width="30%" align="right" class='td1'>结束时间<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1'>
			<input name='endHour' type='text' size='2' id="endHour"  maxlength="2" />时
			<input name='endMinute' type='text' size='2' id="endMinute"  maxlength="2"/>分
		</td>
	</tr>
	</table>
	<input type="hidden" value="" id="updateId" name="updateId">
</div>
<div id="message_dialog" title="" style="display: none" align="center">
	<iframe scrolling="auto" id="message_frame" frameborder=0 align="middle"></iframe>
</div>

<div id="motion_dialog" title="" style="display: none" align="center">
	<iframe scrolling="auto" id="motion_frame" frameborder=0 align="middle"></iframe>
</div>

<div id="contact_dialog" title="" style="display: none" align="center">
	<iframe scrolling="auto" id="contact_frame" frameborder=0 align="middle"></iframe>
</div>

<div id="remotecall_dialog" title="" style="display: none" align="center">
	<iframe scrolling="auto" id="remotecall_frame" frameborder=0 align="middle"></iframe>
</div>
<script type="text/javascript">
var editSmsTime = true;
var dia_img = $j("#forbidden_dialog").dialog( {
	bgiframe :true,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	height : 250,
	width : 400,
	buttons : {
		"确定":function(){
			//检查时间是否正确
			var status = $j("#forbidden").val();
			var _startHour = $j("#startHour").val();
			var _startMinute = $j("#startMinute").val();
			var _endHour = $j("#endHour").val();
			var _endMinute = $j("#endMinute").val();
			var _id = $j("#updateId").val();
			if(status=="true"){
				if(!isHour(_startHour)||!isMinute(_startMinute)||!isHour(_endHour)||!isMinute(_endMinute)){
					alert("时间格式错误");
					return;
				}
			}
			var path='<%=request.getContextPath()%>';
			var _requestUrl = path +"/updateForbiddenTime.htm";
			if(!editSmsTime){
				_requestUrl = path +"/updatePhoneForbiddenTime.htm";
			}
			$j.ajax({
				type: "POST",
	            url: _requestUrl,
	            data:{
	            	forbidden:status,
	            	startHour:_startHour,
	            	startMinute:_startMinute,
	            	endHour:_endHour,
	            	endMinute:_endMinute,
	            	uid:_id
	            },
	            dataType: "text",
	            success: function(result){
	            	 if(result=="success"){
	                 	alert("操作成功！");
	                 	dia_img.dialog('close');
	                 	//window.location.reload();
	                 	document.getElementById("n_form").submit();
	                 }else{
	              	   alert("操作失败！");
	                 }
	            },
	            error: function(){
	              alert("服务器繁忙，请稍后再试！");
	            }
			});
		},
		"取消":function(){
			dia_img.dialog('close');
		}
	}
});

function showEditTimeDialog(_editSms,id,_startHour,_startMinute,_endHour,_endMinute,isForbidden){
	editSmsTime = _editSms;
	$j("#updateId").val(id);
	if(isForbidden){
		$j("#startHour").val(_startHour);
		$j("#startMinute").val(_startMinute);
		$j("#endHour").val(_endHour);
		$j("#endMinute").val(_endMinute);
		$j("#forbidden").get(0).selectedIndex = 0;
	}else{
		$j("#startHour").val("");
		$j("#startMinute").val("");
		$j("#endHour").val("");
		$j("#endMinute").val("");
		$j("#forbidden").get(0).selectedIndex = 1;
	}
	onFobiddenChange();
	dia_img.dialog('open');
}

function onFobiddenChange(){
	var option = $j("#forbidden");
	if(option.val() == "false"){
		$j("#startHour").attr("disabled","disabled");
		$j("#startMinute").attr("disabled","disabled");
		$j("#endHour").attr("disabled","disabled");
		$j("#endMinute").attr("disabled","disabled");
	}else{
		$j("#startHour").removeAttr("disabled");
		$j("#startMinute").removeAttr("disabled");
		$j("#endHour").removeAttr("disabled");
		$j("#endMinute").removeAttr("disabled");
	}
}

function isHour(hour){
	if(hour>=0&&hour<=24){
		return true;
	}
	return false;
}

function isMinute(minute){
	if(minute>=0&&minute<=59){
		return true;
	}
	return false;
}

var message_dialog = $j("#message_dialog").dialog( {
	bgiframe :false,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	title : '查看短信',
	height : 600,
	width : 1000
});

function showMessages(node,_phone,hasNewMsg,_uid){
	var path='<%=request.getContextPath()%>';
	if(hasNewMsg){
		//var PNode = node.parent();
		node.nextAll('img').each(function(){
			 	$j(this).remove();
		});
		$j.ajax({
			type: "GET",
            url: path + "/clearMsgStatus.htm",
            dataType: "text",
            data:{
            	uid:_uid
            },
            success: function(result){
            	
            }
		});
	}
	var messageFrame = $j("#message_frame");
	messageFrame.attr("src",path + "/getMessagesByPhone.htm?phone="+_phone);
	messageFrame.attr("width","960");
	messageFrame.attr("height","550");
	message_dialog.dialog("open");
	
}

var motion_dialog = $j("#motion_dialog").dialog( {
	bgiframe :false,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	title : '查看操作记录',
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	height : 600,
	width : 800
});

function showMotions(_phone){
	var path='<%=request.getContextPath()%>';
	var motionFrame = $j("#motion_frame");
	motionFrame.attr("src",path + "/getMotionByPhone.htm?phone="+_phone);
	motionFrame.attr("width","760");
	motionFrame.attr("height","550");
	motion_dialog.dialog("open");
}

var contact_dialog = $j("#contact_dialog").dialog( {
	bgiframe :false,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	title : '查看通讯录',
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	height : 600,
	width : 1000
});

function showContact(_phone){
	var path='<%=request.getContextPath()%>';
	var contactFrame = $j("#contact_frame");
	contactFrame.attr("src",path + "/getContactByPhone.htm?phone="+_phone);
	contactFrame.attr("width","960");
	contactFrame.attr("height","550");
	contact_dialog.dialog("open");
}

var remotecall_dialog = $j("#remotecall_dialog").dialog( {
	bgiframe :false,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	title : '查看远程电话',
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	height : 600,
	width : 1000
});

function showRemoteCall(_phone){
	var path='<%=request.getContextPath()%>';
	var remoteCallFrame = $j("#remotecall_frame");
	remoteCallFrame.attr("src",path + "/remoteCallList.htm?phone="+_phone);
	remoteCallFrame.attr("width","960");
	remoteCallFrame.attr("height","550");
	remotecall_dialog.dialog("open");
}

</script>
</body>
</html>